﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using QuanLyShop.BUS;
using QuanLyShop.DTO;

namespace SHOP
{
    public partial class TL_QL_DanhMuc : Form
    {
        public TL_QL_DanhMuc()
        {
            InitializeComponent();
        }
        MatHangDTO mathang = new MatHangDTO();
        private void thêmLoạiMặtHàngToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TL_QL_DanhMuc_ThemLoaiMatHang frmThemLoaiMatHang = new TL_QL_DanhMuc_ThemLoaiMatHang();
            frmThemLoaiMatHang.ShowDialog();
        }

        private void sửaLoạiMặtHàngToolStripMenuItem_Click(object sender, EventArgs e)
        {
            mathang.ID_MatHang = dgv_DanhSachLoaiSanPham.SelectedRows[0].Cells["STT"].Value.ToString();
            mathang.TenMatHang = dgv_DanhSachLoaiSanPham.SelectedRows[0].Cells["TenLoaiMatHang"].Value.ToString();
            mathang.ThongTinThem = dgv_DanhSachLoaiSanPham.SelectedRows[0].Cells["ThongTinThem"].Value.ToString();
            mathang.TinhTrang = int.Parse(dgv_DanhSachLoaiSanPham.SelectedRows[0].Cells["TINHTRANG"].Value.ToString());
            TL_QL_DanhMuc_SuaLoaiMatHang frmSualoaiMatHang = new TL_QL_DanhMuc_SuaLoaiMatHang();
            frmSualoaiMatHang.Sua(mathang);
            
            frmSualoaiMatHang.ShowDialog();
        }

        public void TL_QL_DanhMuc_Load(object sender, EventArgs e)
        {
            MatHangBUS BUS = new MatHangBUS();
            DataTable dt = new DataTable();
            dt = BUS.LayDanhSachMatHang();
            dgv_DanhSachLoaiSanPham.DataSource = dt;
            
        }

        private void btnDong_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void xóaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            mathang.ID_MatHang = dgv_DanhSachLoaiSanPham.SelectedRows[0].Cells["STT"].Value.ToString();
            mathang.TenMatHang = dgv_DanhSachLoaiSanPham.SelectedRows[0].Cells["TenLoaiMatHang"].Value.ToString();
            mathang.ThongTinThem = dgv_DanhSachLoaiSanPham.SelectedRows[0].Cells["ThongTinThem"].Value.ToString();
            mathang.TinhTrang = 1;
            MatHangBUS BUS = new MatHangBUS();
            DialogResult result = MessageBox.Show("Bạn có Thật Sự Muốn Xóa Không ? ","Delete",  MessageBoxButtons.YesNo);
            if (result == DialogResult.Yes)
            {
                int kq = BUS.CapNhatMatHang(mathang);
                if (kq == 1)
                {
                    MessageBox.Show("Xóa Thành Công");
                    TL_QL_DanhMuc_Load(sender, e);
                }
                else
                {
                    MessageBox.Show("Xóa Không Thành Công");
                }
            }
            else
            { 

            }
        }

    }
}
